package tq.com.tqstudent.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;

import tq.com.tqstudent.R;

/**
 * @Author rames
 * @date 2019/3/21 16:47
 */
public class PhotoTipsDialog extends Dialog implements View.OnClickListener {
    private ChooseCallback callback;
    private LinearLayout saveLayout;
    private boolean isHiddenSaveLayout = false;

    public PhotoTipsDialog(@NonNull Context context) {
        super(context, R.style.photoTipsDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.dialog_photo_tips);
        findViewById(R.id.camera_tv).setOnClickListener(this);
        findViewById(R.id.album_tv).setOnClickListener(this);
        findViewById(R.id.cancel_tv).setOnClickListener(this);
        saveLayout = findViewById(R.id.save_layout);
        saveLayout.setOnClickListener(this);
        if(isHiddenSaveLayout){
            saveLayout.setVisibility(View.GONE);
        }
    }

    public void hiddenSave(boolean hidden){
        isHiddenSaveLayout = hidden;
    }

    public void setCallback(ChooseCallback callback){
        this.callback = callback;
    }

    @Override
    public void onClick(View view) {
        int index = 0;
        switch (view.getId()){
            case R.id.camera_tv:
                index = 1;
                break;

            case R.id.album_tv:
                index = 2;
                break;

            case R.id.save_layout:
                index = 3;
                break;

            case R.id.cancel_tv:
                this.dismiss();
                return;
        }

        if(null != callback){
            this.dismiss();
            callback.choose(index);
        }
    }

    @Override
    public void show() {
        super.show();
        /**
         * 设置宽度全屏，要设置在show的后面
         */
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.gravity = Gravity.BOTTOM;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        getWindow().setAttributes(layoutParams);
    }

    public interface ChooseCallback{
        void choose(int index);
    }
}
